/**
 * Created by DukeCrushIt on 2015/8/27.
 */
class BuyDiamondPanel extends eui.Component{
    public constructor(){
        super();
        this.skinName = "skins.scene.BuyDiamondSkin";

        //this.addEventListener(egret.Event.ADDED_TO_STAGE, this.addedToStage, this);
    }

    //private addedToStage(evt:egret.Event){
    //    this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.addedToStage, this);
    //    this.diamond_list.dataProvider = new eui.ArrayCollection(Model.diamonds);
    //}

    public diamond_list:eui.List;
    public img_close:eui.Image;
    public partAdded(name:string, instance:any) {
        super.partAdded(name, instance);
        if (name == "img_close") {
            this.img_close = instance;
            this.img_close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
        }else if (name == "diamond_list") {
            this.diamond_list = instance;
            this.diamond_list.itemRenderer =  BuyDiamondItemRender;
            this.diamond_list.dataProvider = new eui.ArrayCollection(Model.diamonds);
        }
    }

    public show(){
        DisplayController.instance().addToAlert(GameConst.GrayMask);
        DisplayController.instance().addToAlert(this);
    }
    private onClose(evt:egret.TouchEvent=null){
        if( evt )
            SoundMgr.getInstance().playEffect(SoundMgr.BTN);
        DisplayController.instance().removeFromAlert(GameConst.GrayMask);
        DisplayController.instance().removeFromAlert(this);
    }
    public measure() {
        super.measure();
        this.x = GameConst.StageW - this.measuredWidth >> 1;
        this.y = GameConst.StageH - this.measuredHeight >> 1;
    }

    private static _instance:BuyDiamondPanel;
    public static getInstance():BuyDiamondPanel{
        if( BuyDiamondPanel._instance == null)
            BuyDiamondPanel._instance = new BuyDiamondPanel();
        return BuyDiamondPanel._instance;
    }
}